<template>
  <view class="up-choose">
    <view
      v-for="(option, index) in options"
      :key="index"
      class="choose-item"
      :style="{ width: itemWidth, height: itemHeight }"
      :class="{ 'choose-item-active': modelValue === index }"
      @click="handleClick(index)"
    >
      {{ option.title }}
    </view>
  </view>
</template>

<script setup lang="ts">
interface Option {
  id: string;
  title: string;
}

interface Props {
  modelValue: number;
  itemWidth: string;
  itemHeight: string;
  options: Option[];
  customClick: boolean;
}

const props = defineProps<Props>();
const emit = defineEmits<{
  'update:modelValue': [value: number];
  'change': [index: number];
}>();

const handleClick = (index: number) => {
  if (!props.customClick) {
    emit('update:modelValue', index);
    emit('change', index);
  }
};
</script>

<style scoped lang="scss">
.up-choose {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 20rpx;
  padding: 10rpx 0;
}

.choose-item {
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2rpx solid #e0e0e0;
  background-color: #ffffff;
  color: #333333;
  font-size: 28rpx;
  font-weight: 400;
  transition: all 0.3s ease;
  height: 80rpx;
  border-radius: 8rpx;
}

.choose-item-active {
  border-color: #1890ff;
  background-color: #1890ff;
  color: #ffffff;
  font-weight: 600;
}

.choose-item:active {
  opacity: 0.8;
}
</style>
